#!/bin/bash

rm resultats_blast.txt 2> error.txt

for proteines_alfa in ./Querys/* ; do {
proteines_beta=`basename $proteines_alfa`
proteines_delta=${proteines_beta%.fa}
llista_proteines="$llista_proteines $proteines_delta"
} done

for protein in $llista_proteines ; do {

	rm resultats_$protein.txt 2> error.txt

	for genomes in P.tricornutum H.arabidopsidis P.ultimum S.parasitica E.siliculosus C.muris C.parvum A.taiwanensis C.owczarzaki P.pallidum C.merolae T.trahens N.gruberi; do {

		patroalfa=`cat ./Querys/$protein.fa | egrep ^">"`
		patrobeta=${patroalfa#*>}
		echo $patrobeta > temppatro
		patro=`cut -f 1 -d " " temppatro`

		blastall -p tblastn -i ./Querys/$protein.fa -d /cursos/BI/genomes/protists/2011/$genomes/genome.fa -o output/$protein.$genomes.txt -m 9 -F F 2> error.txt
		echo ${protein}_$genomes : >> resultats_blast.txt
		egrep "$patro" output/$protein.$genomes.txt | egrep e- >> resultats_blast.txt
		egrep "$patro" output/$protein.$genomes.txt | egrep e- > temp
				
		./searchU.pl < ./Querys/$protein.fa > posicio.txt
		echo ${protein}_$genomes : >> resultats_$protein.txt
		./final.pl < temp >> resultats_$protein.txt

	 	 echo ${protein}_$genomes fet
	} done
} done

		rm temppatro
